<template>
  <div class="view">
    <el-row>
      <ul style="margin:0px;padding:0px">
        <li
          v-for="item in entityData"
          :key="item.id"
          style="line-height:30px;border-bottom: 1px dashed;width:100%;overflow:hidden;word-break:keep-all;white-space:nowrap;text-overflow:ellipsis;"
        >
          <el-tag v-if="item.topFlag === constant.YES_OR_NO.YES" type="danger" size="mini">置顶</el-tag>
          <el-tag v-if="item.importantFlag === constant.YES_OR_NO.YES" type="warning" size="mini">重要</el-tag>
          <a :title="item.title" @click="view(item.id)">
            <span>&nbsp;&nbsp;{{ item.title }}</span>
            <span>([{{ dateFormatter.formatUTCDate(item.publishTime) }})</span>
          </a>
        </li>
      </ul>
    </el-row>
    <div style="color:blue;float:right;line-height:30px">
      <a @click="moreView()">>>更多</a>
    </div>
    <el-dialog :visible.sync="visible" append-to-body width="500px" title="参数配置">
      <el-form>
        <el-table
          :data="configData"
          highlight-current-row
          style="margin-top:5px;"
          border
          width="450px"
        >
          <el-table-column>
            <template slot="header">参数名</template>
            <template slot-scope="scope">{{ scope.row.paramName }}</template>
          </el-table-column>
          <el-table-column>
            <template slot="header">参数值</template>
            <template slot-scope="scope">
              <el-input v-model="scope.row.paramValue" />
            </template>
          </el-table-column>
        </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="confirm()">确定</el-button>
      </div>
    </el-dialog>

    <notice-viewer ref="noticeViewer" />
  </div>
</template>

<script>
import NoticeViewer from '@/modules/support/view/notice/view'
export default {
  name: 'notice-portlet',
  components: { NoticeViewer },
  // 设置绑定参数
  model: {
    prop: 'value',
    event: 'input'
  },
  props: {
    config: {
      type: Array,
      default: function () {
        return []
      }
    },
    dialogVisible: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      visible: false,
      entityData: [],
      configData: this.config

    }
  },
  watch: {
    dialogVisible(val) {
      this.visible = val
    },
    visible(val) {
      this.$emit('update:dialogVisible', val)
    }
  },
  mounted: function () {
    this.getData()
  },
  methods: {
    // 加载数据
    getData() {
      const params = {}
      for (const item of this.configData) {
        params[item.paramCode] = item.paramValue
      }
      this.$api.support.notice.portlet(params)
        .then(res => {
          this.entityData = res.data
        })
    },
    confirm() {
      this.$emit('update:config', this.configData)
      this.visible = false
    },

    view(id) {
      this.$refs.noticeViewer.show(id)
    },
    moreView() {
      // this.$router.push({ path: '/support/notice/noticeViewList' })
      this.$router.push({ name: 'noticeViewList' })
    }
  }
}
</script>

<style lang="scss" scoped>
.view {
  width: 100%;
  a,
  a:active {
    color: #10498f;
    text-decoration: none;
  }
  a:hover,
  a:focus {
    color: #05386b;
    text-decoration: underline;
  }
}
</style>
